GetValueAtLocation Method

The GetValueAtLocation function method allows you to programmatically retrieve the data value that is closest to the provided location.

Example

Temperature=[20,24,21,22,25,30,29,30,25,20,15,19]

Day=FINDGEN(12) * 30 + 15

 

p = PLOT(Day, Temperature, 'Db-1', $

XTITLE = 'Day of Year', $

YTITLE = 'Temperature')

 

; Find the data point closest to Day 150:

xy = p.GetValueAtLocation(150)

print, 'Day=', xy[0], ' Temp=', xy[1]

 

; Now interpolate the data to Day 150:

xy = p.GetValueAtLocation(150, /INTERPOLATE)

print, 'Day=', xy[0], ' Temp=', xy[1]

 

; Draw a crosshair at the interpolated value:

p.Crosshair.LOCATION = xy

p.Crosshair.COLOR = 'red'

p.Crosshair.THICK = 2

IDL prints:

Day= 135.000 Temp= 25.0000

Day= 150.000 Temp= 27.5000

 

As another example, find a data point in an image:

im = IMAGE(/TEST)

xyrgb1 = im.GetValueAtLocation(200.25, 100.4)

print, 'X Y R G B: ', xyrgb1

 

xyrgb2 = im.GetValueAtLocation(200.25, 100.4, /INTERPOLATE)

print, 'X Y R G B: ', xyrgb2

IDL prints:

X Y R G B: 200.000 100.000 105.000 121.000 147.000

 

X Y R G B: 200.250 100.400 126.600 142.600 167.400

Syntax

Result = graphic.GetValueAtLocation( X, Y, Z  [, /DEVICE] [, /INTERPOLATE] [, /NORMAL] )

Return Value

The GetValueAtLocation method returns a vector containing the location and data value of the nearest point. See the table below for the contents of the result.

Arguments

The input arguments and the result depend on the graphic being queried. The following table lists the form of input arguments and the return value.

Graphic

Arguments

Result

Barplot

X

[X, Y]

Contour

X, Y

[X, Y, Z]

Errorplot

X

[X, Y]

Image

X, Y

[X, Y, Value] or [X, Y, R, G, B] or [X, Y, R, G, B, A]

Plot3D

X, Y, Z

[X, Y, Z]

Plot

X

[X, Y]

Polarplot

X, Y

[X, Y]

Streamline

X, Y

[X, Y, U, V]

Surface

X, Y

[X, Y, Z]

Vector

X, Y

[X, Y, U, V]

Note that the output X, Y values will be the location of the nearest data value, and will not necessarily be equal to the input X, Y.

Keywords

DEVICE

Set this keyword if the input X, Y, or Z are in device coordinates. The X, Y, Z will then be automatically converted to data coordinates.

INTERPOLATE

Set this keyword to linearly interpolate the nearest data values to the provided location. The default behavior is to find the nearest data value and return the value and its location. If INTERPOLATE is set then the returned X, Y location will be equal to the input X, Y.

NORMAL

Set this keyword if the input X, Y, or Z are in normalized coordinates. The X, Y, Z will then be automatically converted to data coordinates.

Version History

8.1

Introduced

See Also

ConvertCoord Method, GetData Method, HitTest Method